package com.lwgk.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lwgk.mvp.view.SplashSmoothPlateActivity;

import java.util.List;

/**
 * created by 赵航
 * 联系微信 微信号：zhao--hang--
 * on 2019/7/12
 * --------------------------------------------------------------------------
 * 描述：图片的轮播
 * 注意事项：针对图片有效
 */
public class BannerPagerAdapter extends PagerAdapter {
    private List<Integer> mList;
    private Context mContext;
    public BannerPagerAdapter(List<Integer> list, Context context) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    //是从ViewGroup中移出当前View
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((ImageView) arg2);
    }

    //返回一个对象，这个对象表明了PagerAdapter适配器选择哪个对象放在当前的ViewPager中
    public Object instantiateItem(ViewGroup container, int arg1){
        ImageView imageView = new ImageView(mContext);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        Glide.with(mContext).load(mList.get(arg1)).into(imageView);
        container.addView(imageView);
        return imageView;
    }
}
